<?php
include '../page.php';

header('Content-Type:application/json; charset=utf-8'); #返回json
session_start();
if(empty($_SESSION['userinfo'])){
    //未登录，引导登录
    $result = [
        'code' => '-1',
        'msg' => '未登录，请登录',
    ];
    echo json_encode($result);
    exit ;

}
$pageSize=  $_GET["pageSize"];
$currentPage= $_GET["currentPage"];
$search= $_GET["search"];

$sql = 'SELECT * 
FROM zyh_course ';

if ($search != null){
    $sql = "SELECT * 
    FROM zyh_course 
    where cou_num like '%" . $search . "%' OR cou_year like '%" . $search . "%' OR cou_name like '%" . $search;
}

$page = new Page($pageSize, $currentPage);
$page -> setSql(
    $sql,
    'SELECT COUNT(*) FROM zyh_course'
);


$data = $page -> show();
if (empty($data)){
    $result = [
        'code' => '1',
        'msg' => '获取数据失败',
    ];
}
else{
    $result = [
        'code' => '0',
        'msg' => '获取数据成功',
        'data' => $data
    ];
}


//返回json
echo json_encode($result);
